import 'package:get/get.dart';
import 'package:enterprise_v8/modules/apps/security_basis/security_basis_view.dart';
import 'package:enterprise_v8/modules/auth/login/view.dart';
import 'package:enterprise_v8/modules/auth/splash/splash_view.dart';
import 'package:enterprise_v8/modules/auth/verify/verify_view.dart';
import 'package:enterprise_v8/modules/home/user/help/help_view.dart';
import 'package:enterprise_v8/modules/home/user/scan_login/scan_login_view.dart';
import 'package:enterprise_v8/modules/home/user/settings/permission.dart';
import 'package:enterprise_v8/modules/home/user/settings/setting_list.dart';
import 'package:enterprise_v8/modules/home/user/settings/setting_password/setting_password_view.dart';
import 'package:enterprise_v8/modules/home/user/user_info/common/common_view.dart';
import 'package:enterprise_v8/modules/home/user/user_info/user_info_view.dart';
import 'package:enterprise_v8/modules/home/user/version_info/version_info_view.dart';
import 'package:enterprise_v8/modules/home/view.dart';
import 'package:enterprise_v8/router/app_auth_middleware.dart';

part 'app_routes.dart';

abstract class AppPages {
  AppPages._();

  /// 入口
  static const String initial = Routes.splash;

  static final routes = _generateRoutes();

  static List<GetPage> _generateRoutes() {
    final result = <GetPage>[];
    result.addAll(_generateAuthRoutes());
    result.addAll(_generateHomeRoutes());
    result.addAll(_generatePersonalRoutes());
    result.addAll(_generateSecurityBasisRoutes());
    result.addAll(_generateDangerSourceRoutes());
    result.addAll(_generateDoubleWarningRoutes());
    return result;
  }

  /// 构建页面
  ///
  /// [needAuth] 表示是否需要登录认证才可访问
  static GetPage generatePage({
    required String name,
    required GetPageBuilder page,
    bool needAuth = false,
    String? title,
    Transition? transition,
    List<GetMiddleware>? middlewares,
    Bindings? binding,
  }) {
    final middlewareList = <GetMiddleware>[];

    if (middlewares?.isNotEmpty == true) {
      middlewareList.addAll(middlewareList);
    }

    if (needAuth) {
      middlewareList.add(AppAuthMiddleWare());
    }

    return GetPage(
      name: name,
      page: page,
      title: title,
      // 路由动画
      transition: transition ?? Transition.native,
      middlewares: middlewareList,
      binding: binding,
    );
  }

  /// auth相关
  static List<GetPage> _generateAuthRoutes() {
    return [
      generatePage(
        name: Routes.authLogin,
        page: LoginPage.new,
        needAuth: false,
      ),
      generatePage(
        name: Routes.splash,
        page: SplashPage.new,
        needAuth: false,
      ),
      generatePage(
        name: Routes.verify,
        page: VerifyPage.new,
        needAuth: false,
      )
    ];
  }

  /// 首页
  static List<GetPage> _generateHomeRoutes() {
    return [
      generatePage(
        name: Routes.home,
        page: HomePage.new,
      ),
    ];
  }

  /// 个人页面
  static List<GetPage> _generatePersonalRoutes() {
    return [
      generatePage(
        name: Routes.personalPermission,
        page: PermissionPage.new,
      ),
      generatePage(
        name: Routes.myInfo,
        page: UserInfoPage.new,
      ),
      generatePage(
        name: Routes.myInfoCommon,
        page: CommonPage.new,
      ),
      generatePage(
        name: Routes.personalVersionInfo,
        page: VersionInfoPage.new,
      ),
      generatePage(
        name: Routes.settingPassword,
        page: SettingPasswordPage.new,
      ),
      generatePage(
        name: Routes.personalHelp,
        page: HelpPage.new,
      ),
      generatePage(
        name: Routes.personalSetting,
        page: SettingListPage.new,
      ),
      generatePage(
        name: Routes.personalScanLogin,
        page: ScanLoginPage.new,
      ),
    ];
  }

  /// 安全基础
  static List<GetPage> _generateSecurityBasisRoutes() {
    return [
      generatePage(
        name: Routes.securityBasis,
        page: SecurityBasisPage.new,
      ),
    ];
  }

  /// 重大危险源
  static List<GetPage> _generateDangerSourceRoutes() {
    return [];
  }


  /// 双重预警
  static List<GetPage> _generateDoubleWarningRoutes() {
    return [];
  }

}
